/*
 * Copyright 2010 Michael Nitsche
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package de.mnit.basis.swt.element.steuer;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;

import de.mnit.basis.fehler.Fehler;
import de.mnit.basis.fehler.system.F_Sys_Datei;
import de.mnit.basis.swt.dialog.SWT_Fehler;
import de.mnit.basis.swt.grafik.Bild_SWT;
import de.mnit.basis.swt.grafik.S_Bild_SWT;
import de.mnit.basis.sys.event.S_Verarbeite;

/**
 * @author Michael Nitsche
 */
public class SWT_Knopf_Wechsel extends A_SWT_KnopfWechsel<SWT_Knopf_Wechsel,Button> {

	private String text;


	public SWT_Knopf_Wechsel() {
		this.text=null;
	}

	public SWT_Knopf_Wechsel(String text) {
		this.text=text;
	}


	// FUNKTION

	public void sBild(final Object datei) {
		Fehler.objekt.wenn_Null(datei);
		wennErzeugt(new S_Verarbeite() {
			public void verarbeite() {
				try {
					swt().setImage(Bild_SWT.neu_Direkt(datei).gImage());
				}
				catch(F_Sys_Datei e) {
					SWT_Fehler.zeig(e,true);
				}
			}
		});
	}

	public void sWert(boolean b) {
		swt().setSelection(b);
	}

	public void sText(String text) {
		swt().setText(text);
	}

	// LESEN

	public boolean gWert() {
		return swt().getSelection();
	}

	public S_Bild_SWT gBild() {
		try {
			return Bild_SWT.neu(swt().getImage());
		}
		catch(F_Sys_Datei e) {
			throw SWT_Fehler.zeig(e,true);
		}
	}

	// ERZEUGEN

	protected int style3() {
		return SWT.TOGGLE;
	}

	protected Button roh(Composite basis, int style) {
		return new Button(basis,style);
	}

	protected void init3() {
		if(this.text!=null) swt().setText(this.text);
	}

}
